import { useContext } from 'react';
import { UNSAFE_RouteContext } from 'react-router-dom';
import { RouterConfigObject } from 'src/utils';

export function useCurrentRoute(): RouterConfigObject {
  const context = useContext(UNSAFE_RouteContext);
  return context.matches[context.matches.length - 1]
    .route as unknown as RouterConfigObject;
}
